<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>烟花效果</title>
  <style>
    body {
        margin: 0;
        overflow: hidden;
        background: #000;
    }
    canvas {
        display: block;
    }
  </style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
  const canvas = document.getElementById('canvas');
  const ctx = canvas.getContext('2d');
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;

  const particles = [];
  const colors = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF', '#00FFFF'];

  function Particle(x, y, color) {
      this.x = x;
      this.y = y;
      this.color = color;
      this.radius = Math.random() * 2 + 1;
      this.velocity = {
          x: Math.random() * 10 - 5,
          y: Math.random() * 10 - 5
      };
  }

  Particle.prototype.draw = function() {
      ctx.beginPath();
      ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
      ctx.fillStyle = this.color;
      ctx.fill();
  };

  Particle.prototype.update = function() {
      this.x += this.velocity.x;
      this.y += this.velocity.y;
      this.radius *= 0.96;
  };

  function createFirework(x, y) {
      const color = colors[Math.floor(Math.random() * colors.length)];
      for (let i = 0; i < 50; i++) {
          particles.push(new Particle(x, y, color));
      }
  }

  function animate() {
      requestAnimationFrame(animate);
      ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
      ctx.fillRect(0, 0, canvas.width, canvas.height);

      for (let i = particles.length - 1; i >= 0; i--) {
          particles[i].draw();
          particles[i].update();
          if (particles[i].radius < 0.2) {
              particles.splice(i, 1);
          }
      }
  }

  canvas.addEventListener('click', function(event) {
      createFirework(event.clientX, event.clientY);
  });

  animate();
</script>
</body>
</html>